package com.ynet.middleground.approve.listener.user;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.runtime.ProcessInstance;
import org.springframework.context.annotation.DependsOn;

import com.ynet.middleground.approve.cmd.SpringContextUtils;
import com.ynet.middleground.approve.listener.BaseListener;
import com.ynet.middleground.approve.model.UserCenterModel;

/**
 * @author liulx
 * @description 用户认证完成，更新用户状态监听
 * @date 2019-11-28 10:16
 */
@DependsOn("springContextUtils")
public class UpdateUserStatusListener extends BaseListener implements ExecutionListener {

    private UserCenterModel userCenterModel = SpringContextUtils.getBean(UserCenterModel.class);

    @Override
    public void notify(DelegateExecution delegateExecution) {
        ProcessInstance processInstance =
            processRuntimeModel.getProcessInstance(delegateExecution.getProcessInstanceId());
        String startUserId = processInstance.getStartUserId();
        String channel = getChannel(delegateExecution);
        String operationUserId = getOperationUserId(delegateExecution);
        // 用户认证完成后，状态改成6，详情对接用户中心
        userCenterModel.updateUserState(startUserId, "6", channel, operationUserId);
    }

}
